javascript how to flatten array